﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FrameWork.Log
{

    /// <summary>
    /// 输出类型
    /// </summary>
    public enum LogType
    {
        /// <summary>
        /// 信息
        /// </summary>
        Info,
        /// <summary>
        /// 警告
        /// </summary>
        Waring,
        /// <summary>
        /// 错误
        /// </summary>
        Error
    }

    /// <summary>
    /// 为输出可用时间提供事件存储
    /// </summary>
    public class LogAvilableEventArgs:EventArgs
    {
        /// <summary>
        /// 输出类型
        /// </summary>
        public LogType LogType { get;private set; }
        /// <summary>
        /// 输出消息
        /// </summary>
        public string Message { get;private set; }
        /// <summary>
        /// 关联的对象
        /// </summary>
        public object Tag { get; private set; }
        /// <summary>
        /// 通过指定参数初始化对象实例
        /// </summary>
        /// <param name="Type">消息类型</param>
        /// <param name="Message">消息文本</param>
        /// <param name="Tag">消息附加对象</param>
        public LogAvilableEventArgs(LogType Type,string Message,object Tag=null)
        {
            this.LogType = Type;
            this.Message = Message;
            this.Tag = Tag;
        }
    }

    /// <summary>
    /// 为可输出调试对象提供基类
    /// </summary>
    public abstract class LogableClassBase
    {
        public delegate void LogAvilableEventHandler(object sender,LogAvilableEventArgs e);
        public event LogAvilableEventHandler LogAvilable;
        protected void OnLogAvilable(object sender, LogAvilableEventArgs e)
        {
            if(LogAvilable!=null)
            {
                LogAvilable(sender, e);
            }
        }
        /// <summary>
        /// 输出Log
        /// </summary>
        /// <param name="LogMsg">Log消息</param>
        protected void PrintLog(LogType LogType, string LogMsg, object Tag = null)
        {
            LogAvilableEventArgs e = new LogAvilableEventArgs(LogType, LogMsg, Tag);
            OnLogAvilable(this, e);
        }

    }
}
